/**
 * 
 */
package com.putable.sandbox.threads;

/**
 * From JPL4 pg 342.
 * @author Lucas
 *
 */
public class PingPong implements Runnable {

	private String word;
	private int delay;
	
	public PingPong(String say, int delayTime){
		word = say;
		delay = delayTime;
	}
	
	public void run(){
		try{
			for( ; ; ){
				Thread.sleep(delay); //Wait
				System.out.print(word + " ");
			}
		} catch(InterruptedException e){
			return; //end the thread.
		}
	}
	
	public static void main(String[] args) {
		Runnable ping = new PingPong("ping", 1000);
		Runnable pong = new PingPong("PONG", 3400);
		new Thread(ping, "ping thread").start();
		new Thread(pong, "pong thread").start();
	}

}
